var {
  randomUtils,
  textUtils,
  ocrUtils,
  logUtils,
} = require("../../utils/index");
var adCommon = require("../adCommon");
var adType1 = require("./adType1");
var MAX_AD_INTERVAL = 45;
module.exports = {
  startWatchAd(maxAdCount) {
    adCommon.adCount = 0;
    adCommon.maxAdCount = maxAdCount || 5;
    this.getAdType();
  },
  getAdType() {
    var span = randomUtils.getRandom(MAX_AD_INTERVAL, MAX_AD_INTERVAL + 5);
    for (var index = 0; index < 5; index++) {
      var contents = ["秒后可领"];
      var TextOCR = ocrUtils.captureExistsOneText(contents);
      if (TextOCR) {
        logUtils.info("发现广告:", TextOCR.text);
        adType1.watchAd(span, () => {
          this.getAdType();
        });
        return;
      }
      sleep(2 * 1000);
    }
    logUtils.info("adDouYin", "未知的adType");
  },
};
